import { getUserAddress, getUserOrder } from "@/api/cart";

const state={
  address: [],
  order: {}
}
const mutations={
  // 获取地址
  getUserAddressFn(state, address) {
    state.address = address
  },
  // 获取清单
  getUserOrderFn(state, order) {
    state.order = order
  }
}
const actions={
  // 获取地址
  async getUserAddressFn({commit}) {
    let res = await getUserAddress()
    // console.log(res);
    if (res.data.code === 200) {
      commit('getUserAddressFn', res.data.data)
      return res.data.message
    } else {
      return Promise.reject(new Error(res.data.message))
    }
  },
  // 获取商品清单
  async getUserOrderFn({commit}) {
    let res = await getUserOrder()
    console.log(res);
    if (res.data.code === 200) {
      commit('getUserOrderFn', res.data.data)
    }
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}